<template>


  <div class="app-container">

    <el-card shadow="always" style="margin-top: 20px;">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="160px">
    <el-row :gutter="20">
      <el-col :span="22">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="需求征集" prop="publishId">
            <el-input
              v-model="queryParams.publishId"
              placeholder="请输入需求征集"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="项目名称" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              placeholder="请输入项目名称"
              clearable
              class="full-width"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="研究领域" prop="researchField">
            <el-input
              v-model="queryParams.researchField"
              placeholder="请输入研究领域"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="所属方向" prop="deptId">
            <el-select v-model="queryParams.deptId"  placeholder="请选择所属研究方向" clearable>
                <el-option
                  v-for="dept in deptList"
                  :key="dept.deptId"
                  :label="dept.deptName"
                  :value="dept.deptId"
                />

              </el-select>
          </el-form-item>


        </el-col>
        <el-col :span="24">
          <el-form-item label="申报人" prop="applicant">
            <el-input
              v-model="queryParams.applicant"
              placeholder="请输入申报人"
              clearable

              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="申报时间" prop="applicationTime">
            <el-date-picker clearable
              v-model="queryParams.applicationTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择申报时间"
              style="width: 95%;"
              class="no-icon-date">
            </el-date-picker>
          </el-form-item>



        </el-col>
      </el-row>
      </el-col>

      <!-- 第二列 -->
      <el-col :span="2">
        <el-row>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-row>
      </el-col>
      </el-row>
    </el-form>
    </el-card>
    <el-card shadow="always" style="margin-top: 20px;">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:application:add']"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:application:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:application:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="applicationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="通知标题" align="center" prop="publishId">
        <template slot-scope="scope">
          {{ getPublishLabel(scope.row.publishId) }}
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="研究领域" align="center" prop="researchField" />
      <el-table-column label="所属方向"  width="160" align="center" prop="deptId">
        <template slot-scope="scope">
          {{ getDeptLabel(scope.row.deptId) }}
        </template>
      </el-table-column>
      <el-table-column label="申报人" align="center" prop="applicant" />
      <el-table-column label="申报时间" align="center" prop="applicationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applicationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="填报人" align="center" prop="filler" />
      <el-table-column label="执行期限" align="center" prop="executionPeriod" width="180">
      </el-table-column>
      <el-table-column label="经费(万元)"  width="150" align="center" prop="funding" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="操作"  width="300" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
            <el-button
               type="text"
              style="color: #409EFF;"

              @click="handleView(scope.row)"
              v-hasPermi="['system:application:query']"
            >查看</el-button>

            <el-button
              type="text"
              :style="{ color: isPublishClosed(scope.row.publishId) ? '#909399' : '#67C23A' }"

              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:application:edit']"
              :disabled="isPublishClosed(scope.row.publishId)"
            >
              {{ isPublishClosed(scope.row.publishId) ? '已截止' : '修改' }}
            </el-button>
          </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </el-card>

    <!-- 添加或修改项目征集发布对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">

          <el-row :gutter="20">

            <el-col :span="8">
              <el-card shadow="always" style="margin: 20px;">
                <el-descriptions title="需求征集信息" :column="1">
                  <el-descriptions-item label="通知标题"  > {{this.formData.guideFileName}}</el-descriptions-item>
                  <el-descriptions-item label="归口部门">{{ formData.responsibleDepartment }}</el-descriptions-item>
                  <el-descriptions-item label="级别">{{this.formData.level}}</el-descriptions-item>
                  <el-descriptions-item label="指南类别"  > {{this.formData.guideCategory}}</el-descriptions-item>
                  <el-descriptions-item label="申报期限">{{ formData.applicationDeadline }}</el-descriptions-item>
                  <el-descriptions-item label="申报状态">
                    {{ formatStatus(this.formData.status) }}
                  </el-descriptions-item>
                  <el-descriptions-item label="发布人">
                    {{this.formData.publisher}}
                  </el-descriptions-item>
                  <el-descriptions-item label="发布时间">
                    {{this.formData.publishTime}}
                  </el-descriptions-item>


                </el-descriptions>
                <el-divider ></el-divider>
                <el-descriptions title="附件文档" :column="1" border>
                  <el-descriptions-item v-for="(row, index) in formData.fileRows" :key="'file-' + index" :label="'文件 ' + (index + 1)">
                    <div>
                      <p>文件名称: {{ row.fileClassName }}</p>
                      <p>上传人: {{ row.uploader }}</p>
                      <p>上传时间: {{ row.uploadTime }}</p>


                      <p>
                        <template v-if="row.fileInfo && row.fileInfo.length > 0">
                          <div v-for="(file, fileIndex) in row.fileInfo" :key="fileIndex" style="margin-top: 5px;">
                            <el-link
                              type="primary"
                              target="_blank"
                              @click="handleDownload(file)"
                            >
                              {{ file.originalName }}
                            </el-link>

                            <span style="margin-left: 8px; color: #909399; font-size: 12px">
                              ({{ (file.fileSize/1024).toFixed(2) }} KB)
                            </span>
                          </div>
                        </template>
                        <span v-else style="color: #909399">无附件</span>


                      </p>
                    </div>
                  </el-descriptions-item>
                </el-descriptions>
              </el-card>
            </el-col>

            <el-col :span="16">
              <el-card shadow="always" style="margin-top: 20px;">
              <el-divider ><i class="el-icon-collection"></i>  基本信息</el-divider>
              <el-row :gutter="20">

                <el-col :span="12">
                  <el-form-item label="文件指南名" prop="publishId">
                    <el-select :disabled="readonlyPublishId"
                      v-model="form.publishId"
                      placeholder="请选择文件指南"

                      :style="{width: '100%'}"
                      @change="handlePublishIdChange">
                      <el-option
                          v-for="project in selectPublishList"
                          :key="project.id"
                          :label="project.guideFileName"
                          :value="project.id"
                        />
                      </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目名称" prop="projectName">
                    <el-input v-model="form.projectName" placeholder="请输入项目名称" clearable :style="{width: '100%'}"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="研究领域" prop="researchField">
                    <el-input v-model="form.researchField" placeholder="请输入研究领域" clearable :style="{width: '100%'}"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="研究方向" prop="deptId">
                    <el-select v-model="form.deptId" placeholder="请选择所属方向" clearable :style="{width: '100%'}">
                      <el-option
                        v-for="dept in deptList"
                        :key="dept.deptId"
                        :label="dept.deptName"
                        :value="dept.deptId"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申报人" prop="applicant">
                    <el-input v-model="form.applicant" placeholder="请输入申报人" clearable :style="{width: '100%'}">
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="申报时间" prop="applicationTime" >
                    <el-date-picker clearable
                      v-model="form.applicationTime"
                      type="date"
                      :style="{width: '100%'}"
                      value-format="yyyy-MM-dd"
                      placeholder="请选择申报时间">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="填报人" prop="filler">
                    <el-input v-model="form.filler" placeholder="请输入填报人" clearable :style="{width: '100%'}">
                    </el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="执行期限" prop="executionPeriod" >
                    <el-date-picker
                      v-model="form.executionPeriod"
                      type="daterange"
                      range-separator=" - "
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      value-format="yyyy-MM-dd"
                      :style="{width: '100%'}"
                      clearable
                    />
                  </el-form-item>
                </el-col>


                <el-col :span="12">
                  <el-form-item label="经费" prop="funding">
                    <el-input v-model="form.funding" placeholder="请输入经费" clearable :style="{width: '100%'}">
                      <template slot="append">万元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="联系电话" prop="phone">
                    <el-input v-model="form.phone" placeholder="请输入手机号" :maxlength="11" show-word-limit clearable
                    prefix-icon='el-icon-mobile' :style="{width: '100%'}"></el-input>
                  </el-form-item>

                </el-col>
              </el-row>

              <el-divider ><i class="el-icon-folder-opened"></i>  附件文档</el-divider>
              <file-upload-table v-model="form.fileRows" :show-add="true" />
            </el-card>
        </el-col>

        </el-row>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="success" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-drawer
      title="需求填报信息"
      :visible.sync="drawer"
      size="50%">

      <el-card shadow="always" style="margin: 20px;">
        <el-descriptions title="基本信息"  border  :column="2">
          <el-descriptions-item label="项目名称"  > {{this.formView.projectName}}</el-descriptions-item>
          <el-descriptions-item label="研究领域">{{ formView.researchField }}</el-descriptions-item>
          <el-descriptions-item label="所属方向">{{getDeptLabel(formView.deptId) }}</el-descriptions-item>
          <el-descriptions-item label="申报人"  > {{this.formView.applicant}}</el-descriptions-item>
          <el-descriptions-item label="申报时间">{{ formView.applicationTime }}</el-descriptions-item>
          <el-descriptions-item label="填报人">
            {{ this.formView.filler }}
          </el-descriptions-item>
          <el-descriptions-item label="执行期限">
            {{this.formView.executionPeriod}}
          </el-descriptions-item>

          <el-descriptions-item label="经费(万元)">
            {{this.formView.funding}}
          </el-descriptions-item>
		      <el-descriptions-item label="联系电话">
            {{this.formView.phone}}
          </el-descriptions-item>


        </el-descriptions>
      </el-card>
      <el-card shadow="always" style="margin: 20px;">
        <el-descriptions title="附件文档" :column="1" border>
          <el-descriptions-item v-for="(row, index) in formView.fileRows" :key="'file-' + index" :label="row.fileClassName || '未命名文件'">
            <div>
              <p>
                <template v-if="row.fileInfo && row.fileInfo.length > 0">
                  <div v-for="(file, fileIndex) in row.fileInfo" :key="fileIndex" style="margin-top: 5px;">
                    <el-link
                      type="primary"
                      target="_blank"
                       @click="handleDownload(file)"
                    >
                      {{ file.originalName }}
                    </el-link>

                    <span style="margin-left: 8px; color: #909399; font-size: 12px">
                      ({{ (file.fileSize/1024).toFixed(2) }} KB)
                    </span>
                  </div>
                </template>
                <span v-else style="color: #909399">无附件</span>
              </p>
              <p>上传人: {{ row.uploader }}</p>
              <p>上传时间: {{ row.uploadTime }}</p>

            </div>
          </el-descriptions-item>
        </el-descriptions>
      </el-card>
    </el-drawer>


  </div>
</template>

<script>
import { listApplication, getApplication, delApplication, addApplication, updateApplication } from "@/api/sci/application";
import { downloadMinioFile } from '@/api/common/common';
import { listDept } from '@/api/system/dept';
import { getPublish,listPublish } from "@/api/sci/publish";
import FileUploadTable from '@/views/sci/components/FileUploadTable';


export default {
  name: "Application",
  components: {
    FileUploadTable
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目征集发布表格数据
      applicationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      drawer: false,

      readonlyPublishId: false, // 控制是否只读

      // 时间范围
      daterangeExecutionPeriod: [],


      username : this.$store.state.user.nickName,

	    deptList: [],

      publishList: [],

      selectPublishList: [],


      publishId: null,
      // 查询参数
      queryParams: {
        pageSize: 10,
        publishId: null,
        projectName: null,
        researchField: null,
        deptId: null,
        applicant: null,
        applicationTime: null,
        filler: null,
        executionPeriod: null,
        funding: null,
        phone: null,
      },
      // 表单参数
      form: {
        fileRows: [
          {
            fileClassName: '',
            uploader: '',
            uploadTime: '',
            fileInfo: []
          }
        ]
      },
      formView: {
        fileRows: [] // 初始化为空数组
      },

      formData: {
        fileRows: [] // 初始化为空数组
      },
      // 表单校验
      rules: {
        publishId: [
          { required: true, message: "关联的项目征集发布ID不能为空", trigger: "blur" }
        ],
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        researchField: [
          { required: true, message: "研究领域不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "所属方向不能为空", trigger: "blur" }
        ],
        applicant: [
          { required: true, message: "申报人不能为空", trigger: "blur" }
        ],
        applicationTime: [
          { required: true, message: "申报时间不能为空", trigger: "blur" }
        ],
        filler: [
          { required: true, message: "填报人不能为空", trigger: "blur" }
        ],

        funding: [
          { required: true, message: "经费不能为空", trigger: "blur" }
        ],
        phone: [{
          required: true,
          message: '请输入手机号',
          trigger: 'blur'
        }, {
          pattern: /^1(3|4|5|7|8|9)\d{9}$/,
          message: '手机号格式错误',
          trigger: 'blur'
        }],
        fileRows: {
          fileClassName: [
            { required: true, message: '请选择文件名称', trigger: 'change' }
          ],

          fileInfo: [
            { required: true, message: '请上传附件', trigger: 'change' }
          ],
        },
      }
    };
  },
  created() {
    this.getList();
	  this.getDeptList();
    this.getPublishList();
    this.loadApplicationData();
  },

  watch: {
    '$route'(to, from) {
       if(to.name==='Application'){
         this.loadApplicationData(); // 路由变化时重新加载
       }
    }
  },

  methods: {
    /** 查询项目征集发布列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeExecutionPeriod && '' != this.daterangeExecutionPeriod) {
        this.queryParams.params["beginExecutionPeriod"] = this.daterangeExecutionPeriod[0];
        this.queryParams.params["endExecutionPeriod"] = this.daterangeExecutionPeriod[1];
      }
      this.getPublishList();
      listApplication(this.queryParams).then(response => {
        this.applicationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    loadApplicationData() {
      this.publishId = this.$route.query.id || this.$route.params.id;
      if (this.publishId) {
        this.open = true;
        this.title = "需求信息填写";
        this.getPublistInfo();

          // 设置为只读/禁用
        this.readonlyPublishId = true;

        this.form.fileRows[0].uploader = this.username;
      }
    },

    getPublistInfo() {
      if(this.publishId!==null && this.publishId!==undefined)
      {
        getPublish(this.publishId).then(response => {
            if (response.data && response.data.fileRows) {
              response.data.fileRows = response.data.fileRows.map(fileRow => {
                try {
                  // 如果fileInfo是字符串则转换为数组，否则保持原样
                  fileRow.fileInfo = typeof fileRow.fileInfo === 'string'
                    ? JSON.parse(fileRow.fileInfo)
                    : fileRow.fileInfo;
                } catch (e) {
                  console.error('fileInfo解析失败：', e);
                  fileRow.fileInfo = [];
                }
                return fileRow;
              });
            }
            this.formData = response.data;
            // 自动设置 form.publishId 的值
            this.form.publishId = response.data.id;

          }).catch(err => {
            this.$message.error("加载申报信息失败");
          });
        }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        publishId: null,
        projectName: null,
        researchField: null,
        deptId: null,
        applicant: null,
        applicationTime: null,
        filler: null,
        executionPeriod: null,
        funding: null,
        phone: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        fileRows: [  // 保持基础结构
          {
            fileClassName: '',
            uploader: '',
            uploadTime: '',
            fileInfo: []
          }
        ]
      };
      this.resetForm("form");
    },

    resetView() {
      this.formView = {
        id: null,
        publishId: null,
        projectName: null,
        researchField: null,
        deptId: null,
        applicant: null,
        applicationTime: null,
        filler: null,
        executionPeriod: null,
        funding: null,
        phone: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        fileRows: [  // 保持基础结构
          {
            fileClassName: '',
            uploader: '',
            uploadTime: '',
            fileInfo: []
          }
        ]
      };
      this.resetForm("formView");
    },
    handleDatetimeUpdate(index, datetime) {
      // Update the corresponding uploadTime field
      this.$set(this.form.fileRows[index], 'uploadTime', datetime);
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeExecutionPeriod = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.readonlyPublishId = false;
      this.title = "需求信息填写";
      this.form.fileRows[0].uploader = this.username;

      this.getPublistInfo();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getApplication(id).then(response => {
        this.form = response.data;
        this.form.executionPeriod = this.parseExecutionPeriod(this.form.executionPeriod);
        this.open = true;
        this.readonlyPublishId = false;
        this.title = "需求信息修改";
        this.getPublistInfo();
      });
    },

    handlePublishIdChange(value) {
      if (value !== null && value !== undefined) {
        this.publishId = value;
        this.getPublistInfo(); // 示例：加载项目详情
      }
    },

    handleView(row) {
      this.resetView();
      const id = row.id || this.ids
      getApplication(id).then(response => {

        if (response.data && response.data.fileRows) {
          response.data.fileRows = response.data.fileRows.map(fileRow => {
            try {
              // 如果fileInfo是字符串则转换为数组，否则保持原样
              fileRow.fileInfo = typeof fileRow.fileInfo === 'string'
                ? JSON.parse(fileRow.fileInfo)
                : fileRow.fileInfo;
            } catch (e) {
              console.error('fileInfo解析失败：', e);
              fileRow.fileInfo = [];
            }
            return fileRow;
          });
        }
        this.formView = response.data;

        this.drawer = true;
      });
    },
    handleDownload(file) {
      const fileName = file.url; // 替换为实际的文件名
      downloadMinioFile(fileName);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (!fileRows || fileRows.length === 0) {
            this.$message.error('请上传文件');
            return;
          }
          for (let i = 0; i < fileRows.length; i++) {
            const row = fileRows[i];
            if (!row.fileClassName || row.fileClassName.trim() === '') {
              this.$message.error(`第 ${i + 1} 行文件类型不能为空`);
              return;
            }

            if (!row.fileInfo || JSON.parse(row.fileInfo).length === 0) {
              this.$message.error(`第 ${i + 1} 行附件不能为空`);
              return;
            }
          }
          this.form.executionPeriod = this.formatExecutionPeriod(this.form.executionPeriod);
          if (this.form.id != null) {
            updateApplication(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplication(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目征集发布编号为"' + ids + '"的数据项？').then(function() {
        return delApplication(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/publish/export', {
        ...this.queryParams
      }, `publish_${new Date().getTime()}.xlsx`)
    },


    isPublishClosed(publishId) {
      if (!publishId) return true;

      const publish = this.publishList.find(item => item.id === publishId);
      return !publish || publish.status === 0;
    },


    addRow() {
      this.form.fileRows.push({
        fileClassName: '',
        uploader: this.username,
        uploadTime: '',
        fileInfo: [],
      });
    },
    removeRow(index) {
      if (this.form.fileRows.length > 1) {
        this.form.fileRows.splice(index, 1);
      } else {
        this.$message.warning('至少需要保留一行');
      }
    },

    formatStatus(status) {
      return status === '1' || status === 1 ? '申报中' : '已关闭';
    },
    getDeptList() {
      listDept().then(response => {
        this.deptList = response.data.filter(dept => dept.deptId !== 100);      });
    },
    getDeptLabel(deptId) {
      const dept = this.deptList.find(d => d.deptId === deptId);
      return dept ? dept.deptName : '';
    },
    getPublishList() {
      listPublish().then(response => {
        this.publishList = response.rows;
        this.selectPublishList = response.rows.filter(item => item.status !== 0);
      });
    },

    getPublishLabel(publishId) {
      const publish = this.publishList.find(p => p.id === publishId);
      return publish ? publish.guideFileName : '';
    },

    // 字符串 -> 数组
    parseExecutionPeriod(str) {
      return str ? str.split(' - ') : [];
    },

    // 数组 -> 字符串
    formatExecutionPeriod(arr) {
      return Array.isArray(arr) ? arr.join(' - ') : '';
    },


  }
};
</script>

<style lang="scss" scoped>
.full-width {
  width: 100%;
}
.full-width .el-input__inner,
.full-width .el-date-editor input {
  width: calc(100% - 30px); /* 减去 icon 宽度 */
  padding-right: 30px;        /* 保持文本居中 */
}
.no-icon-date ::v-deep .el-input__suffix {
  display: none;
}
</style>
